<?php

session_start();
require( 'util.php' );

if (is_logged_as_volunteer())
{
	validate_action_get( array( 'mid', 'page' ) );
	validate_action_post( array( 'aid' ) );
	
	$go_back_url = "list.php?mid={$_GET['mid']}&page={$_GET['page']}";
	
	require( 'db.php' );
    $sql = "INSERT INTO activity( p_id, u_id ) VALUES ( {$_POST['aid']}, {$_SESSION['u_id']} )";
    $result = mysql_query( $sql ) or alert_and_redirect( '你已经报名参加了这个活动', $go_back_url );
	
	alert_and_redirect( '报名成功', $go_back_url );
}
else
{
	report_err_and_exit( '必须以普通志愿者的身份登录' );
}

?>